<?php 
namespace app\model;

use think\Model;
use think\Db;

class commodity extends Model{
	// 获取未审核商品列表
	public static function getUnauditedList($num){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->join("picture p","co.picture_id = p.picture_id")
				->where([
					"co.is_pass" => 0,
					"co.is_delete" => 0,
					"co.is_sold" => 0,
				])
				->paginate($num);
		return $res;
	}

	// 获取已审核商品列表
	public static function getAuditedList($num){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->join("picture p","co.picture_id = p.picture_id")
				->where([
					"co.is_pass" => 1,
					"co.is_delete" => 0,
					"co.is_sold" => 0,
				])
				->paginate($num);
		return $res;
	}

	// 获取售完商品列表
	public static function getSoledList($num){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->join("picture p","co.picture_id = p.picture_id")
				->where([
					"co.is_pass" => 1,
					"co.is_delete" => 0,
					"co.is_sold" => 1,
				])
				->paginate($num);
		return $res;
	}

	// 获取商品信息
	public static function getInfo($id){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->where([
					"co.commodity_id" => $id,
				])
				->find();
		return $res;
	}

	// 按分类获取商品
	public static function getCommodityByCategory($category_id){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->where([
					"co.category_id" => $category_id,
					"co.is_delete" => 0,
					"co.is_pass" => 1,
					"co.commodity_num" => [">",0],
				])
				->paginate();
		return $res;
	}

	// 按关键字获取商品
	public static function getCommodityByWord($word){
		$res = Db::name('commodity co')
				->join("category ca","co.category_id = ca.category_id")
				->where([
					"co.commodity_name" => ["like","%{$word}%"],
					"co.is_delete" => 0,
					"co.commodity_num" => [">",0],
				])
				->paginate();
		return $res;
	}
}

 ?>